<?php

class Products extends Controller {

	function index()
	{
		$data['main_content'] = 'add_object';
		$this->load->view('includes/template', $data);		
	}
	
	function add()
	{
		$data['main_content'] = 'add_object';
		$this->load->view('includes/template', $data);
	}
	
	function create_object() {
	
		$this->load->library('form_validation');
		
		// field name, error message, validation rules
		$this->form_validation->set_rules('name', 'Name', 'trim|required|callback_objectname_not_exist|xss_clean');
		$this->form_validation->set_rules('base_price', 'Base Price', 'trim|required|xss_clean');
		$this->form_validation->set_rules('sale_endtime', 'Sale Endtime', 'trim|required||xss_clean');
		$this->form_validation->set_rules('photo', 'Photo', 'trim|xss_clean');
		$this->form_validation->set_rules('description', 'Description', 'trim|required|xss_clean');
		
		
		if($this->form_validation->run() == FALSE)
		{
			$this->load->view('add_object');
		}
		
		else
		{			
			$this->load->model('objectship_model');
			
			if($query = $this->objectship_model->create_object())
			{
				//$data['main_content'] = 'creation_successful';
				$data['main_content'] = 'upload_pic';
				$this->load->view('includes/template', $data);
			}
			else
			{
				$this->load->view('add_object');			
			}
		}
		
	}	
	
	function objectname_not_taken($login)
	{
		$this->form_validation->set_message('name', 'That %s already exists. Please chose a different object name and try again.');

		if ($this->objectship_model->taken_objectname($name))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
		function remove($Object) {
		
	}
	
	function viewAll() {
		
	}
	
	function edit($Object) {
		
	}
}
